﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace _04_MvvmLight框架.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        public RelayCommand<string> ShowCommand { get; set; }

        private string? _message;
        public string? Message
        {
            get { return _message; }
            set
            {
                _message = value;
                RaisePropertyChanged();
            }
        }

        public MainViewModel()
        { 
            // 注册一个消息
            Messenger.Default.Register<string>(this, "Token1", ShowMessage);

            ShowCommand = new RelayCommand<string>(Show);
        }

        private void ShowMessage(string value)
        {
            MessageBox.Show(value);
        }

        public void Show(string content)
        {
            Message = "接到通知";
            // 给Token1发消息
            Messenger.Default.Send(content, "Token1");
        }
    }
}
